var fetch2 = function(pageIndex){
  pageIndex = pageIndex || 1
  //短期没有使用/长期未活动 unusedInShortTimeTable
  $.ajax({
    type: 'GET',
    url: houseInfo.ajaxUrl[1].page(pageIndex,10),
    beforeSend: function (xhr) {
      xhr.setRequestHeader('Authorization', tokenPgAuth);
      xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
    }
  }).done(function (response) {
    //一房多人的总数 总数使用在slider里面一个 图标一个 分页处三个地方
    console.log('2短期没有使用',response)
    var options = {
      bDestroy:true,
      searching: false,
      bPaginate: false ,//表格分页
      bSort: false,
      bLengthMenu: false,
      bInfo: false,
      pageLength:10, // 每页显示数量
      bAutoWidth: false,
      bLengthChange: false,
      bProcessing: true,
      data: response,
      fnPageChange:function(settings){
        changePage(settings,'.unusedInShortTimeTable',1)
      },
      columns: [
        {
          data: "simpleaddr",
          class:'addr',
          bSortable: false,
          align: 'left',
          render: function (data, type, full, meta) {
            if (!data) data = '--';
            return data
          }
        },
        {
          data: "housenumber",
          class: 'digit ta',
          bSortable: false,
          render: function (data, type, full, meta) {
            if (!data) data = '--';
            return data
          }
        },
        {
          data: "stats_per_lock_for_active_formal",   //钥匙数量
          align: 'left',
          className: 'ta',
          bSortable: false,
          render: function (data, type, full, meta) {
            return full.stats_per_lock_for_active_formal.tally_keys ? full.stats_per_lock_for_active_formal.tally_keys: '--'
          }
        },
        {
          data: "stats_per_lock_event_for_active_formal",    //最近一次开门时间  读数据"2020-09-25T13:19:58"
          align: 'left',
          className: 'ta',
          bSortable: false,
          render: function (data, type, full, meta) {
            if(full.stats_per_lock_event_for_active_formal){
              var time=full.stats_per_lock_event_for_active_formal.last_open_at || ''
              return time.replace("T","  ") || ''
            }else{
              return '--'
            }
          }
        }
      ],
    };
    options.fnInitComplete =  function (settings) {
      $.ajax({
        type: 'GET',
        url: houseInfo.ajaxUrlTotal[1].page(1,1),
        beforeSend: function (xhr) {
          xhr.setRequestHeader('Authorization', tokenPgAuth);
          xhr.setRequestHeader('Accept-Profile', 'api-ailock-analysis-v1');
          xhr.setRequestHeader('Prefer', 'count=exact');
          xhr.setRequestHeader('cache-control','no-cache')
          xhr.setRequestHeader('pragma','no-cache')
        }
      }).done(function (res,type,request1) {
        settings.oFeatures.bPaginate = true;
        houseInfo.total[1] = pgApiUtils.getTotal(request1); // 一房多人的总数
        $('.' + houseInfo.totalDomId[1] + 1).text(houseInfo.total[1])
        $('#' + houseInfo.totalDomId[1] + 2).text(houseInfo.total[1])
        settings._pgAiDisplayLength =   houseInfo.total[1]
        settings.oFeatures.bProcessing = false
        settings.oApi._fnAddOptionsHtml(settings)
        settings.oApi._fnDraw(settings)

        var myOptions = jQuery.extend(options, {
          fnPageChange : function(settings){
            changePage(settings,'.unusedInShortTimeTable',0)
          },
          fnInitComplete : function(settings){
            settings.oFeatures.bPaginate = true;
            settings._pgAiDisplayLength = houseInfo.total[1]
            settings.oFeatures.bProcessing = false
            settings.oApi._fnAddOptionsHtml(settings)
            settings.oApi._fnDraw(settings)
            houseInfo.bindEvent[1]()
          }
        });
        houseInfo.tables[1][1] = $('.unusedInShortTimeTable').eq(1).dataTable(myOptions);

        if(typeof(callback) === 'function') {
          callback()
        }
      })

    }

    houseInfo.tables[1][0] = $('.unusedInShortTimeTable').eq(0).dataTable(options);

  })
}

// 7天内行为暂时废除
/*houseInfo.bindEvent[1] = function () {
  $(".unusedInShortTimeTable").each(function (index,item){
    $(item).on("click","td.addr",function(){//给tr或者td添加click事件
      var trDom = $(this).parent()[0]
      var data=houseInfo.tables[1][index].api().row(trDom).data();//获取值的对象数据
      console.log(data);
      getRenterListAndHouseMaster(data)
    })
  })
}*/

houseInfo.bindEvent[1] = function () {
  $(".unusedInShortTimeTable").each(function (index,item){
    $(item).on("click","tr",function(){//给tr或者td添加click事件
      //var trDom = $(this).parent()[0]
      var data=houseInfo.tables[1][index].api().row(this).data();//获取值的对象数据
      getRenterListAndHouseMaster(data)
    })
  })
}
